<?php 
class cls_serve_favorite extends cls_serve_base
{
	function check_if_related_data($customerid, $favoriteid)
	{
		$favorite_data = cls_data_base::get_instance($this->name);
		
		$result = $favorite_data->check_if_related_data($customerid, $favoriteid);
		
		return $result;
	}
	
	function get_all_favorite($customerid)
	{
		$favorite_data = cls_data_base::get_instance($this->name);
	
		$result = $favorite_data->get_all_favorite($customerid);
	
		if(!$result)
		{
			return return_info(true);
		}
		else
		{
			return return_info(true, $result);
		}
	}
	
	function add_favorite($customerid, $productid)
	{
		$favorite_exist = $this->check_favorite_exist($customerid, $productid);
		if($favorite_exist)
		{
			return return_info(false, "收藏已经存在");
		}
		$favorite_data = cls_data_base::get_instance($this->name);
	
		$result = $favorite_data->add_favorite($customerid, $productid);
	
		if($result > 0)
		{
			return return_info(true);
		}
		else
		{
			return return_info(false);
		}
	}
	
	function delete_favorite($customerid, $favoriteid)
	{
		$related = $this->check_if_related_data($customerid, $favoriteid);
		if(!$related)
		{
			return return_info(false, "该收藏不属于当前用户");
		}
		
		$favorite_data = cls_data_base::get_instance($this->name);
	
		$result = $favorite_data->delete_favorite($favoriteid);
	
		if($result == 1)
		{
			return return_info(true);
		}
		else
		{
			return return_info(false);
		}
	}
	
	function check_favorite_exist($customerid, $productid)
	{
		$favorite_data = cls_data_base::get_instance($this->name);
	
		$result = $favorite_data->check_favorite_exist($customerid, $productid);
	
		return $result;
	}
}
?>